export const StringUtils = {
    isEmpty: function (input) {
        return input == null || input == '';
    },
    isNotEmpty: function (input) {
        return !this.isEmpty(input);
    },
    trimToEmpty: function (input) {
        return input == null ? '' : this.trim(input);
    },
    startsWith: function (input, prefix) {
        return input.indexOf(prefix) === 0;
    },
    endsWith: function (input, suffix) {
        return input.lastIndexOf(suffix) === 0;
    },
    contains: function (input, searchSeq) {
        return input.indexOf(searchSeq) >= 0;
    },
    equals: function (input1, input2) {
        return input1 == input2;
    },
    equalsIgnoreCase: function (input1, input2) {
        return input1.toLocaleLowerCase() == input2.toLocaleLowerCase();
    },
    containsWhitespace: function (input) {
        return this.contains(input, ' ');
    },
    //生成指定个数的字符
    repeat: function (ch, repeatTimes) {
        var result = '';
        for (var i = 0; i < repeatTimes; i++) {
            result += ch;
        }
        return result;
    },
    deleteWhitespace: function (input) {
        return input.replace(/\s+/g, '');
    },
    rightPad: function (input, size, padStr) {
        return input + this.repeat(padStr, size);
    },
    leftPad: function (input, size, padStr) {
        return this.repeat(padStr, size) + input;
    },
    substringAfter: function (str, separator) {
        if (this.isEmpty(str)) {
            return str;
        } else if (separator == null) {
            return "";
        } else {
            let pos = str.indexOf(separator);
            return pos == -1 ? "" : str.substring(pos + separator.length);
        }
    },
};
